﻿#pragma once
#include "yzrutil.h"
#include "DSP.h"
#include "EnvelopDetector.h"
#include "interpolator/Interpolator.h"

namespace yzrilyzr_dsp{
	ECLASS(Compressor, public DSP){
	private:
	u_sample_rate sampleRate;
	EnvelopDetector envDetect;
	u_sample preGain=1;
	u_sample postGain=1;
	u_sample finalGain=0;
	std::shared_ptr<yzrilyzr_interpolator::Interpolator> ioFunction;
	public:
	Compressor();
	Compressor(u_sample preGain, u_sample postGain,
			   u_time_ms attack, u_time_ms hold, u_time_ms release,
			   int limitType,
			   std::shared_ptr<yzrilyzr_interpolator::Interpolator> ioFunction);
	u_sample procDsp(u_sample src)override;
	void init(u_sample_rate sampleRate)override;
	void resetMemory()override;
	std::shared_ptr<DSP> cloneDSP()override;
	void cloneParam(DSP * obj1)override;
	u_sample getFinalGain()const{
		return finalGain;
	}
	yzrilyzr_lang::String toString()const override;
	private:
	void setState(int newState);
	};
}